package com.java.common.cloud.service;

import com.java.common.cloud.CloudStorageConfig;
import com.java.common.utils.file.FileUploadUtils;
import com.java.common.utils.tool.StringUtils;
import com.java.common.utils.tool.Tool;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

public class LocalCloudStorageService extends CloudStorageService {

    public LocalCloudStorageService(CloudStorageConfig config) {
        this.config = config;
    }

    @Override
    public String upload(byte[] data, String path) {
        return null;
    }

    @Override
    public String uploadSuffix(MultipartFile file) {
        try {
            String fileName = "upload";
            if (StringUtils.isNotEmpty(config.getLocalFileName())) {
                fileName = config.getLocalFileName();
            }
            // 上传文件路径
            String filePath = Tool.getProjectPath() + fileName;
            // 上传并返回新文件url
            String url = FileUploadUtils.upload(filePath, file);
            return url;
        } catch (Exception e) {
            throw new RuntimeException("上传文件失败");
        }
    }

    @Override
    public String uploadSuffix(byte[] data, String suffix) {
        return null;
    }

    @Override
    public String upload(InputStream inputStream, String path) {
        return null;
    }

    @Override
    public String uploadSuffix(InputStream inputStream, String suffix) {
        return null;
    }

}
